

/**
 * 参数中间件(所有的中间件千万不要放入耗时的操作！！！！)
 * @param req
 * @param res
 * @param next
 * @constructor
 */
module.exports =  function  ParamAndRes(req, res, next) {
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-type,Accept,X-Access-Token,X-Key,X-Token');
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Credentials', 'true');
    res.header("Content-Type", "text/html;charset=utf-8");
    const method = req.method.toLowerCase();
    //post请求 request 获取参数
    if (method === 'options') {
        res.sendStatus(200);
       return;
    }
    if (method === 'post') {
        Reflect.set(req,'args',req.body);
        //get请求
    } else if (method === 'get') {
        Reflect.set(req,'args',req.query);
    }
    //创建响应数据
    Reflect.set(res,'wrap', function (s, m, d) {
        return {
            code: s,
            msg: m,
            data: d
        }
    });

    next();
}
